<template>
  <div class="myContainer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="12" class="myLineHeight_40px">{{this.title}}</el-col>
      <el-col :span="12" class="myTextAlignRight">
        <el-button type="primary" class="myBgGreen" @click="add" v-if="isShow(184)">新 增</el-button>
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="8">
        <el-date-picker
          v-model="time"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-col>
      <el-col :span="3">
        <template>
          <el-select 
            v-model="deleteStatus"
            clearable
            placeholder="删除标记">
            <el-option
              v-for="item in deleteStatusList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="3">
        <el-input placeholder="请输入关键词" v-model="kw"></el-input>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" class="myBgGreen" @click="fuzzySearch">查 询</el-button>
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
      <el-col :span="24">
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="list"
          :border = true
          :stripe = true
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            prop="STORE_ID"
            width="55">
          </el-table-column>
          <el-table-column
            prop="ADPLACENAME"
            label="广告位名称"
            >
          </el-table-column>
          <el-table-column
            prop="ADNAME"
            label="广告名称"
            >
          </el-table-column>
          <el-table-column
            prop="ADDESC"
            label="广告描述"
            >
          </el-table-column>
          <el-table-column
            prop="ADPIC"
            label="广告图片"
            >
            <template scope="scope">
              <a :href='EBIZ_SHOW_PIC_API+scope.row.ADPIC' target="_blank">
                <img :src='EBIZ_SHOW_PIC_API+scope.row.ADPIC' width="50" height="50"/>
              </a>
            </template>
          </el-table-column>
          <el-table-column
            prop="JUMPTYPE"
            label="类型"
            >
            <template scope="scope">
              <span>{{scope.row.JUMPTYPE | JUMPTYPEType}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="BEGINTIME"
            label="开始时间"
            >
          </el-table-column>
          <el-table-column
            prop="ENDTIME"
            label="结束时间"
            >
          </el-table-column>
          <el-table-column
            label="删除标记"
            >
            <template scope="scope">
              <span v-if="scope.row.DELETED==0">未删除</span>
              <span class="myColorRed" v-else>已删除</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            width="100">
            <template scope="scope">
              <el-button type="text primary" @click="modify(scope.row.AD_ID)" class="modifly" size="small" v-if="isShow(185)">编 辑</el-button> 
              <span v-if="scope.row.DELETED==0">
                | <el-button type="text warning" class="look" size="small" @click="onDelete(scope.row.AD_ID)" v-if="isShow(186)">删 除</el-button>
              </span>
            </template>
          </el-table-column>
        </el-table>

        <div class="block">                    
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page_num"
            :page-sizes="[10, 15]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
    padding-bottom: 5px;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
  .myColorRed{
    color: #f00;
  }
</style>

<script>
  import { getAdverisingList , deleteAd } from '@/api/advertising';
  import qs from "querystring";
  import { EBIZ_SHOW_PIC_API } from '@/config/baseUrl';
  export default {
    data(){
      return{  
        title:"餐饮广告管理",    
        list:[],  

        total:null, //总条数  
        page_num: 1, //当前页码
        page_size: 10, //每页显示多少条 

        selectedLd:"-1",
        ldList:[],
        building_id:-1,
        lookObj:{},
      
        id:null,
        index:null,
        idArr:[],
        area_id: -1,
        pages:1000,
        loading:false,
        multipleSelection: [],

        EBIZ_SHOW_PIC_API:EBIZ_SHOW_PIC_API,

        kw:"",
        startTime:"",
        endTime:"",
        deleteStatus:"",
        deleteStatusList:[{value:0,label:"未删除"},{value:1,label:"已删除"}],

        deleteDialog:false,
        newDeptDialogVisible:false,
        time:[]
      }
    },
    created() {
      document.title=this.title;
      this.fetchList();
    },

    filters: {
      JUMPTYPEType: function(value) {     
        let src = '';
        switch (value) {
          case 2:
            src = 'url';
          break;
          case 10:
            src = '超市商品详情';
          break;
          case 11:
            src = '餐饮商品详情';
          break;
          case 12:
            src = '团购商品详情';
          break;
          case 20:
            src = '超市商品分类列表';
          break;
          case 21:
            src = '餐饮商品分类列表';
          break;
          case 22:
            src = '团购商品分类列表';
          break;
         
        }
        return src;    
      }
  },


    methods:{
       fetchList() {
        let vm = this;
        if(vm.time){
          vm.startTime=this.time[0];
          vm.endTime=this.time[1];
        }else{
          vm.startTime="";
          vm.endTime="";
        }
        const params = {
          page: vm.page_num,
          rows: vm.page_size,
          ADPLACE_ID: 3,
          ADNAME:encodeURI(vm.kw),
          DELETED:vm.deleteStatus,
          start:vm.startTime,
          end:vm.endTime
        }

        vm.loading = true;
        getAdverisingList(params)
        .then(response => {
          let res = response.data;
          vm.list = res.rows;
          vm.total = res.total;
        
          vm.loading = false;
        })
        .catch(error => {
          vm.loading = false;
        });
      },
      fuzzySearch() {
         this.fetchList();
      },
      handleSizeChange(val) {
        this.page_size = val;
        this.fetchList();
      },
      handleCurrentChange(val) {
        this.page_num = val;
        this.fetchList();
      },
      add:function(){
         this.$router.push({
           path:'/cyggglComponents',
           query: {type: 'add'}
         })
      },
//
//
     modify:function(adId){
       this.$router.push({
         path:'/cyggglComponents',
         query: {type: 'update', id: adId}
       })
     },

      deleteData:function (datas,index) {
        this.idArr.push(datas.cell_id);
        this.index = index;
        this.lookObj = datas
      },
      //-----经营时间弹出-------
     
      //-------删除

     //----页码---
      handleSelectionChange(val) {
        this.multipleSelection = val;
        if(val.length!=0){
          for(var i = 0;i<val.length;i++){
            this.idArr.push(val[i].area_id)
          }
        }else{
          this.idArr = [];
        }
       
        //console.log(JSON.stringify(this.idArr))
      },
       indexMethod(index) {
          return (this.page_num-1)*this.page_size + index + 1
      },
      onDelete(ad_ID){//删除
        let vm=this;
        vm.$confirm('您确定要删除这条数据吗？', '提示', {//弹出框
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let params={
            AD_ID:ad_ID
          }
          deleteAd(qs.stringify(params)).then(response => {//逻辑删除商品
            vm.fetchList();
            vm.$message({
              type: 'success',
              message: '执行成功!'
            });
          }).catch(error => {
            vm.$message.error("执行失败！");
          })
        }).catch(() => {
          vm.$message({
            type: 'info',
            message: '已取消执行'
          });          
        });
      }
    }

  }


</script>



